/*!
 @Title: js常用 2019-12-16 13:23:16
 @Description：js处理归总 格式:方法名_yc
 @Site:  asiry.cn
 @Author: yc1.0
 */
/**
 *一个数组是否有重复值,返回二维数组
 */
function strArgEval_yc(arrAy) {
    var res = [];
    arrAy.sort();
    for (var i = 0; i < arrAy.length;) {
        var count = 0;
        for (var j = i; j < arrAy.length; j++) {
            if (arrAy[i] == arrAy[j]) {
                count++;
            }
        }
        res.push([arrAy[i], count]);
        i += count;
    }
    return res;
}

/**
 *Datatime时间处理
 */
function formatDate_yc(date,format)
{
    if(!date)
    {
        return '';
    }
    else if(typeof(date) == "string")
    {
        if("null"==date)
        {
            return '';
        }
        return date;
    }
    else if(typeof(date) == "undefined" || "undefined"==date)
    {
        return '';
    }
    else if(typeof(date) == "object")
    {
        var year = date.year + 1900;
        var month = (date.month + 1)>=10 ? (date.month + 1):"0"+(date.month + 1);
        var day = date.date>=10 ? date.date:"0"+date.date;
        var hours = date.hours>=10 ? date.hours:"0"+date.hours;
        var minutes = date.minutes>=10 ? date.minutes:"0"+date.minutes;
        var seconds = date.seconds>=10 ? date.seconds:"0"+date.seconds;
        if(format && "hh:mi:ss" == format)
        {
            return hours+":"+minutes+":"+seconds
        }
        else if(format && "yyyy-mm-dd" == format)
        {
            return year+"-"+month+"-"+day
        }
        else if(format && "yyyy-mm-dd hh:mi:ss" == format)
        {
            return year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds
        }
        else if(format && "yyyy/mm/dd" == format)
        {
            return year+"/"+month+"/"+day
        }
        else if(format && "yyyy/mm/dd hh:mi:ss" == format)
        {
            return year+"/"+month+"/"+day+" "+hours+":"+minutes+":"+seconds
        }
        return year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds;
    }
    return date;
}
/**
 *Js将分钟转换成天、时、分
 */
function timeStampSwitch_yc(StatusMinute) {
    var day = parseInt(StatusMinute / 60 / 24);
    var hour = parseInt(StatusMinute / 60 % 24);
    var min = parseInt(StatusMinute % 60);
    StatusMinute = "";
    if (day > 0) {
        StatusMinute = day + "天";
    }
    if (hour > 0) {
        StatusMinute += hour + "小时";
    }
    if (min > 0) {
        StatusMinute += parseFloat(min) + "分钟";
    }
    //三元运算符 传入的分钟数不够一分钟 默认为0分钟，else return 运算后的StatusMinute
    return StatusMinute == "" ? "0分钟": StatusMinute;
}

/**
 * js替换所有字符
 * @param s1
 * @param s2
 */
String.prototype.replaceAll_yc  = function(s1,s2){
    return this.replace(new RegExp(s1,"gm"),s2);
}